package week5;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Ex47 {
    public static void main(String[] args) {
        int n = 1000000;
        int[] prime = new int[n];
        int c = 0;
        boolean[] isVisit = new boolean[n + 1];
        for (int i = 2; i <= n; ++i) {
            if (!isVisit[i])
                prime[++c] = i;
            for (int j = 1; j <= c && i * prime[j] <= n; ++j) {
                isVisit[i * prime[j]] = true;
                if (i % prime[j] == 0)
                    break;
            }
        }
        List<Integer> list = new ArrayList<>();
        list.add(210);
        int sumOfPrimeFactor;
        int t, ti;
        Set<Integer> set = new HashSet<>();
        for (int m = 211; list.size() < 4 && m < Integer.MAX_VALUE; ++m) {
            if (isVisit[m]) {
                set.clear();
                t = m;
                ti = 1;
                while (t > 1) {
                    if (t % prime[ti] == 0) {
                        t /= prime[ti];
                        set.add(prime[ti]);
                    } else ti++;
                }
                sumOfPrimeFactor = set.size();
                if (sumOfPrimeFactor == 4) {
                    if (list.get(list.size() - 1) + 1 == m)
                        list.add(m);
                    else {
                        list.clear();
                        list.add(m);
                    }
                }
            }
        }
        if (list.size() == 4)
            System.out.println(list.get(0));
        else
            System.out.println("bounds limited");
    }
}
